package com.lx;

/**
 * Created by lanyxp on 2020/6/20
 */
public class Remessages {
    /***
     *组装请求参数
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Request<T> CreateRequest(T data) {
        return new Request<>(data);
    }

    public static Response successs() {
        return success(null);
    }

    /***
     * 成功
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Response<T> success(T data) {
        RequestHader requestHader = RequestHader.getRequestHader();
        ResponseHader responseHader = new ResponseHader(CommonResultCode.SUCCESS.getCode(), CommonResultCode.SUCCESS.getDesc(), requestHader.getSeqNo());
        return new Response<>(responseHader, data);
    }

    public static <T> Response<T> success() {
        RequestHader requestHader = RequestHader.getRequestHader();
        ResponseHader responseHader = new ResponseHader(CommonResultCode.SUCCESS.getCode(), CommonResultCode.SUCCESS.getDesc(), requestHader.getSeqNo());
        return new Response<>(responseHader, null);
    }

    /***
     * 失败
     * @param resultCode
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Response fail(ResultCode resultCode, T data) {
        RequestHader requestHader = RequestHader.getRequestHader();
        final ResponseHader responseHader = new ResponseHader(resultCode.getCode(), resultCode.getDesc(), requestHader.getSeqNo());
        return new Response<>(responseHader, data);
    }

    public static Response fail(ResultCode result) {
        if (result == null) {
            return fail(CommonResultCode.SYSTEM_ERROR);
        } else {
            return fail(result.getCode(), result.getDesc());
        }
    }

    public static Response fail(String code, String desc) {
        if (code == null || code.equals("")) {
            code = CommonResultCode.SYSTEM_ERROR.getCode();
        }
        if (desc == null || desc.equals("")) {
            desc = CommonResultCode.SYSTEM_ERROR.getDesc();
        }
        RequestHader requestHader = RequestHader.getRequestHader();
        final ResponseHader responseHader = new ResponseHader(code, desc, requestHader.getSeqNo());
        return new Response<>(responseHader, null);
    }

    public static Response fail() {
        return fail(CommonResultCode.SYSTEM_ERROR);
    }

    public class success {
    }
}
